﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.ServiceModel;
using AcceptServer;
using BLL;
using Common;
using Model;
using PLSServer;

namespace PositionServer.Service
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple, IncludeExceptionDetailInFaults = true)]
    class PositionService : IPositionService
    {
        public int TestWCF()
        {
            return 1;
        }


     
        readonly BUser _bUser = new BUser();
        
        readonly BRole _bRole = new BRole();
         
        readonly BGmapoverlay _bGmapoverlay = new BGmapoverlay();

        private readonly BDevice _bDevice = new BDevice();
        private readonly BGpsHistory _bGpsHistory = new BGpsHistory();
  
        public UserInfo CheckUserWithReturn(string userName, string password)
        {
            return _bUser.CheckUserWithReturn(userName, password);
        }
        
        public string GetClientVersion()
        {
            return Common.OperateConfig.GetClientVersion();
        }
     
      
        public List<DeviceInfo> GetAllDeviceLocation()
        {
            lock (AcceptMainForm.DeviceList.SyncRoot)
            {
                List<DeviceInfo> list = new List<DeviceInfo>();

                 
                list.AddRange(AcceptMainForm.DeviceList.Values.Cast<DeviceInfo>());
                //AcceptMainForm.DeviceList.Values.Cast<DeviceInfo>().ToList();
                return list;
            }
        }
 
 
        /// <summary>
        /// Verify client platform user name and password 
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool CheckUser(string userName, string password)
        {
            bool bCheckUser = _bUser.CheckUser(userName, password);
            Console.WriteLine(DateTime.Now.ToString() + "bCheckUser--" + bCheckUser.ToString());
            return bCheckUser;

        }

        public bool ChangePassWordByUserName(string userName, string newPwd)
        {
            return _bUser.ChangePassWordByUserName(userName, newPwd);
        }

 

        public bool UserAdd(UserInfo model)
        {
            return _bUser.Add(model);
        }

        public bool UserUpdate(UserInfo model)
        {
            return _bUser.Update(model);
        }

        public bool UserDelete(int id)
        {
            return _bUser.Delete(id);
        }

        public bool UserDeleteList(string idlist)
        {
            return _bUser.DeleteList(idlist);
        }

        public DataSet UserGetList(string strWhere)
        {
            return _bUser.GetList(strWhere);
        }

        public bool UserExist(string userName)
        {
            return _bUser.Exists(userName);
        }

        public bool RoleAdd(RoleInfo model)
        {
            return _bRole.Add(model);
        }

        public bool RoleUpdate(int id, string name, string permission, string remark)
        {
            return _bRole.Update(id, name, permission, remark);
        }

        public string[] GetRoleInfoByUserName(string username)
        {
            return _bRole.GetRoleInfoByUserName(username);
        }

        public bool RoleDelete(int id)
        {
            return _bRole.Delete(id);
        }

        public bool RoleDeleteList(string idlist)
        {
            return _bRole.DeleteList(idlist);
        }

        public DataSet RoleGetList(string strWhere)
        {
            return _bRole.GetList(strWhere);
        }

        public bool RoleExist(string roleName)
        {
            return _bRole.Exists(roleName);
        }

         
      

        public bool GmapoverlayAdd(Model.GmapoverlayInfo model)
        {
            return _bGmapoverlay.Add(model);
        }

        public bool GmapoverlayUpdate(Model.GmapoverlayInfo model)
        {
            return _bGmapoverlay.Update(model);
        }

        public bool GmapoverlayDelete(int id)
        {
            return _bGmapoverlay.Delete(id);
        }

        public Model.GmapoverlayInfo GmapoverlayGetModel(int id)
        {
            return _bGmapoverlay.GetModel(id);
        }

        public DataSet GmapoverlayGetList(string strWhere)
        {
            return _bGmapoverlay.GetList(strWhere);
        }

        public DataSet GmapoverlayGetListByParameter(string parameter, string parameterVaule)
        {
            return _bGmapoverlay.GetList(parameter, parameterVaule);
        }

        public int GmapoverlayGetRecordCount(string strWhere)
        {
            return _bGmapoverlay.GetRecordCount(strWhere);
        }


        public DataSet DeviceGetList(string strWhere)
        {
            return _bDevice.GetList(strWhere);
        }

        public DataSet DeviceGpsHistoryGetList(string strEmi, DateTime startTime, DateTime endTime)
        {
            return _bGpsHistory.GetList(strEmi, startTime, endTime);
        }

    }
}
